//
//  LJEmoctionCell.swift
//  LJ表情键盘
//
//  Created by Raymond on 15/12/28.
//  Copyright © 2015年 liu. All rights reserved.
//

import UIKit

class LJEmoctionCell: UICollectionViewCell {
    /// 模型
    var emoction: LJEmoction? {
        didSet{
            if let pngPath = emoction?.pngString {
                emoctionButton.setImage(UIImage(contentsOfFile: pngPath), forState: UIControlState.Normal)
                emoctionButton.setImage(UIImage(contentsOfFile: pngPath), forState: UIControlState.Highlighted)
            }else{
                emoctionButton.setImage(nil, forState: UIControlState.Normal)
                emoctionButton.setImage(nil, forState: UIControlState.Highlighted)
            }
            
            emoctionButton.setTitle(emoction?.emoji, forState: UIControlState.Normal)
            
            // 设置删除按钮
            if emoction!.isRemoveEmoction {
                emoctionButton.setImage(UIImage(named: "compose_emotion_delete"), forState: UIControlState.Normal)
                emoctionButton.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Highlighted)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI() {
        addSubview(emoctionButton)
        emoctionButton.frame = CGRectInset(bounds, 3, 3)
//        emoctionButton.backgroundColor = UIColor.blueColor()
    }

    
    // MARK: - 懒加载
    private lazy var emoctionButton: UIButton = {
        let button = UIButton()
        button.titleLabel?.font = UIFont.systemFontOfSize(32)
        // 禁止与用户交互
        button.userInteractionEnabled = false
        return button
    }()
}
